package com.zhangyan.controller;

import com.zhangyan.entity.Dept;
import com.zhangyan.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    // 增加部门
    @PostMapping
    public int addDept(@RequestBody Dept dept) {
        return deptService.insertDept(dept);
    }

    // 删除部门
    @DeleteMapping("/{deptId}")
    public int deleteDept(@PathVariable Integer deptId) {
        return deptService.deleteDept(deptId);
    }

    // 修改部门
    @PutMapping
    public int updateDept(@RequestBody Dept dept) {
        return deptService.updateDept(dept);
    }

    // 多条件查询部门
    @GetMapping
    public List<Dept> queryDept(@RequestParam(required = false) String dname,
                                @RequestParam(required = false) String loc) {
        return deptService.queryDept(dname, loc);
    }
}
